﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Modules_vsDetail_AddNew : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
        this.btnCancel.Attributes.Add("onclick","return ClearAll()");

        if (!this.IsPostBack) {
            ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
            LoadCategory();
        }
    }

    

    private void LoadCategory() {
        using (WebData db = new WebData())
        {
            this.cbbidCat.DataSource = db.tbl_CatTagss.GetAll();
            this.cbbidCat.DataBind();
        }
    }

    private void AddNew() {
        String strMess = "";
        int id = 0;
            try
            {

                using (WebData db = new WebData())
                {
                    DataLibrary.tbl_DetailCate news = new DataLibrary.tbl_DetailCate();
                    news.IdCat = Convert.ToInt32(cbbidCat.SelectedValue);
                    news.Title = txtTieude.Text;                    
                    news.IsActive = 1;                    
                    news.OrderId = Convert.ToInt32(txtorderId.Text);
                    news.IdLang = 1;
                    news.Description = txtNoidung.Text;
                    id = db.tbl_DetailCates.InsertOnSubmit(news);
                }

            }
            catch (Exception err)
            {
                strMess = Message.Insert_err + "! vì lỗi " + err.Message.ToString();
            }
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Err", "alert('" + strMess + "');", true);
       if(id!=-1)
           Response.Redirect(ViewState["URLReferrer"].ToString());

    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        AddNew();
    }

}